<?php
namespace App\Api\Transformers;

use App\Master;
use League\Fractal\TransformerAbstract;

/**
 * Class MasterAllTransformer
 * @package App\Api\Transformers
 */
class MasterAllTransformer extends TransformerAbstract
{
    /**
     * @var array
     */
    protected $availableIncludes  = [
        'videos',
    ];

    /**
     * @param Master $master
     * @return array
     */
    public function transform(Master $master)
    {
        $avatarUrl = "http://yuejian.app/uploads/avatars/";
        return [
            'master_id' => $master['id'],
            'master_name' => $master['master_name'],
            'master_intro' => $master['master_intro'],
            'master_avatar' => $avatarUrl.$master['master_avatar'],
            'mvideos' => isset($master->videos) ?  $master->videos : 'Null',
            'questions' => isset($master->questions) ?  $master->questions : 'Null',
        ];
    }

    /**
     * @param Master $master
     * @return \League\Fractal\Resource\Collection
     */
    public function includeVideos(Master $master)
    {
        $mvideos = $master->videos;

        return $this->collection($mvideos, new MasterVideoTransformer);
    }
}